package ${package.Controller};

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
        <#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * ${table.comment!} 前端控制器
 *
 * @author ${author}
 * @date ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@RestController
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Resource
    private I${entity}Service ${entity}Service;

    /**
    * 新增${entity}
    */
    @PostMapping
    public Result add(@RequestBody ${entity} ${entity}) {
        boolean flag = ${entity}Service.save(${entity});
        if (!flag) {
            return Result.FAIL();
        }
        return Result.SUCCESS();
    }

    /**
    * 删除${entity}
    */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id) {
        boolean flag = ${entity}Service.removeById(id);
        if (!flag) {
            return Result.FAIL();
        }
        return Result.SUCCESS();
    }

    /**
    * 更新${entity}
    */
    @PutMapping
    public Result update(@RequestBody ${entity} ${entity}) {
        boolean flag = ${entity}Service.updateById(${entity});
        if (!flag) {
            return Result.FAIL();
        }
        return Result.SUCCESS();
    }

    /**
    * ${entity}详情
    */
    @GetMapping("/{id}")
    public Result detail(@PathVariable String id) {
        ${entity} ${entity} = ${entity}Service.getById(id);
        if (${entity} == null) {
            return Result.FAIL();
        }
        return Result.SUCCESS(${entity});
    }

    /**
    * ${entity}分页列表
    *
    * @param pageNum  页码
    * @param pageSize 每页记录数
    */
    @PostMapping("/page")
    public Result page(@RequestBody ${entity} ${entity}, @RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.SUCCESS();
    }
}
</#if>
